<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     enterprise_default
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
?>
<?php
/**
 * Edit shipping address template
 *
 * @see Enterprise_GiftRegistry_Block_Customer_Address_Edit
 *
 */
/* @var $this Enterprise_GiftRegistry_Block_Customer_Address_Edit */
?>


<div class="fieldset">
    <h2 class="legend"><?php echo $this->__('Shipping Address') ?></h2>
    <ul class="form-list">
    <?php if ($this->customerHasAddresses()) : ?>
        <li>
            <label for="address_type_or_id"><?php echo $this->__('Select a shipping address from your address book or enter a new address.') ?></label>
            <div class="input-box"><?php echo $this->getAddressHtmlSelect('address_type_or_id') ?></div>
        </li>
    <?php endif ?>
        <li id="shipping-new-address-form"<?php if ($this->customerHasAddresses()): ?> style="display:none;"<?php endif ?>>
            <ul>
                <li class="fields"><?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getAddress())
                        ->setFieldNameFormat('address[%s]')->toHtml() ?>
                </li>
                <li>
                    <label for="address:company"><?php echo $this->__('Company') ?></label>
                    <div class="input-box">
                        <input type="text" id="address:company" name="address[company]" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Company')) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>"/>
                    </div>
                </li>
        <?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
                <li>
                    <label for="address:street1" class="required"><em>*</em><?php echo $this->__('Address') ?></label>
                    <div class="input-box">
                        <input type="text" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Street Address')) ?>" name="address[street][]" id="address:street1" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet(1)) ?>" class="input-text <?php echo $_streetValidationClass ?>" />
                    </div>
                </li>
        <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
        <?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
                <li class="add-field">
                    <div class="input-box">
                        <input type="text" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Street Address %s', $_i)) ?>" name="address[street][]" id="address:street<?php echo $_i ?>" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet($_i)) ?>" class="input-text <?php echo $_streetValidationClass ?>"/>
                    </div>
                </li>
        <?php endfor; ?>
                <li class="fields">
                    <div class="field">
                        <label for="address:city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
                        <div class="input-box">
                            <input type="text" title="<?php echo Mage::helper('core')->quoteEscape($this->__('City')) ?>" name="address[city]" value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="address:city"/>
                        </div>
                    </div>
                    <div class="field">
                        <label for="address:region" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
                        <div class="input-box">
                            <select id="address:region_id" name="address[region_id]" title="<?php echo Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>" class="validate-select" style="display:none;">
                            <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                        </select>
                        <script type="text/javascript">
                        //<![CDATA[
                        document.observe("dom:loaded", function() {
                            $('address:region_id').setAttribute('defaultValue',  "<?php echo $this->getAddress()->getRegionId() ?>");
                        })
                        //]]>
                        </script>
                        <input type="text" id="address:region" name="address[region]" value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;" />
                    </div>
                    </div>
                </li>
                <li class="fields">
                    <div class="field">
                        <label for="address:postcode" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
                        <div class="input-box">
                            <input type="text" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Zip/Postal Code')) ?>" name="address[postcode]" id="address:postcode" value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>" class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>"/>
                        </div>
                    </div>
                    <div class="field">
                        <label for="address:country_id" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
                        <div class="input-box">
                            <?php echo $this->getCountryHtmlSelect($this->getAddress()->getCountryId(), 'address[country_id]', 'address:country_id');?>
                        </div>
                    </div>
                </li>
                <li class="fields">
                    <div class="field">
                        <label for="address:telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
                        <div class="input-box">
                            <input type="text" name="address[telephone]" value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Telephone')) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>" id="address:telephone"/>
                        </div>
                    </div>
                    <div class="field">
                        <label for="address:fax"><?php echo $this->__('Fax') ?></label>
                        <div class="input-box">
                            <input type="text" name="address[fax]" value="<?php echo $this->escapeHtml($this->getAddress()->getFax()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Fax')) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('fax') ?>" id="address:fax"/>
                        </div>
                    </div>
                </li>
            </ul>
        </li>
    </ul>
</div>
<script type="text/javascript">
//<![CDATA[

function changeShippingAddressType(event) {
    var el = Event.element(event);
    var show_form = false;

    if ((!el) || (el.getValue() == 'new')) {
        show_form = true;
    }

    if ( $('shipping-new-address-form')) {
        if (show_form) {
            $('shipping-new-address-form').show();
        } else {
            $('shipping-new-address-form').hide();
        }
    }
}
if ($('address_type_or_id')) {
    $('address_type_or_id').observe('change', changeShippingAddressType);
}

new RegionUpdater('address:country_id', 'address:region', 'address:region_id', regionJSON, undefined, 'zip');

<?php if ($this->getEntity()->getShippingAddress()): ?>
    if ($('address_type_or_id')) {
        $('address_type_or_id').setValue('new');
    }
    $('shipping-new-address-form').show();
<?php endif; ?>

//]]>
</script>
